package cn.source.zk.service.impl;

import cn.source.zk.domain.entity.ChannelSort;
import cn.source.zk.domain.entity.Sort;
import cn.source.zk.mapper.ZkChannelSortMapper;
import cn.source.zk.service.IZkChannelSortService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

@Slf4j
@Service
public class ZkChannelSorServiceImpl implements IZkChannelSortService {

    @Autowired
    private ZkChannelSortMapper channelSortMapper;

    // 新增通道排序
    public int addChannelSort(ChannelSort channelSort) {
        return channelSortMapper.addChannelSort(channelSort);
    }

    // 修改通道排序
    public int editChannelSort(ChannelSort channelSort) {
        return channelSortMapper.editChannelSort(channelSort);
    }

    // 删除通道排序
    public int removeByChannelId(int ChannelId) {
        return channelSortMapper.removeByChannelId(ChannelId);
    }

    // 通过通道id查询排序
    public List<Integer> findSortIdByChannelId(Long ChannelId) {
        return Collections.emptyList();
    }

    public List<Sort> exclusionSortList(List<Long> sortList) {
        log.info(sortList.toString());

        if (sortList != null) {
            sortList.removeIf(Objects::isNull);  // 移除所有 null 元素
            if (sortList.isEmpty()) {
                sortList = null;  // 如果移除后为空，则设为 null
            }
        }
        return channelSortMapper.exclusionSortList(sortList);
    }


}
